package com.spring.partypark.web.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.spera.genutil.TokenUtil;
import com.spring.partypark.web.dao.PartyParkMapper;
import com.spring.partypark.web.model.Appointment;
import com.spring.partypark.web.service.PartyParkService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;
import com.spring.tools.MyTools;
import com.sso.api.web.dao.SsoMapper;

@Service
public class PartyParkServiceImpl implements PartyParkService{
	@Resource
	private PartyParkMapper partyParkMapper;
	
	@Resource
	private JedisCache jedisCache;

	@Resource
	private SsoMapper ssoMapper;
	
	
	//得到主题类型
	@Override
	public Map<String, Object> getThemeList(String name) throws Exception {
		Map<String, Object> m = new HashMap();
		
		/*Map<String, Object> t = checkToken(token);
		if (t != null) {

			return t;

		}

		String c_user_id = redisCache.lindex(token, 0);*/
		
		
			/*
			HashMap hmc=MyTools.checkIsNotNull(rechargecard_id);
			if(ApplicationUtils.isNotNull(hmc)){
				return hmc;
			}
			
			
			HashMap hm=new HashMap();
			hm.put("card_id", rechargecard_id);
			hm.put("c_family_member_id", c_family_member_id); SpUtil*/
			
			List<HashMap> list = partyParkMapper.getThemeList(name);
			
			m.put(ApplicationUtils.DATASET, list);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "查询成功");

		
		return m;
	}


	
	//预约
	@Override
	public Map<String, Object> appoint(String token, String party_themeID, String serviceTargetID, 
			String serviceTargetName,String peopleNumber, String executeTime, String kids_parkID) throws Exception {
	
		Map<String, Object> m = new HashMap();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);

			HashMap hmc=MyTools.checkIsNotNull(party_themeID,serviceTargetID,serviceTargetName,peopleNumber,executeTime,kids_parkID);
			if(ApplicationUtils.isNotNull(hmc)){
				return hmc;
			}
			
			
			HashMap hm=new HashMap();
			hm.put("cUserID", c_user_id);
			hm.put("party_themeID", party_themeID); 
			hm.put("serviceTargetID", serviceTargetID); 
			hm.put("serviceTargetName", serviceTargetName); 
			hm.put("peopleNumber", peopleNumber); 
			hm.put("executeTime", executeTime); 
			hm.put("kids_parkID", kids_parkID); 
			
			
			List<String> list=ssoMapper.checkIsMember(hm);
			
			//判断是否是会员
			if(list.size()==0){
				hm.put("isMember", 0); 
			}else{
				hm.put("isMember", 1); 
				hm.put("memberNumber", list.get(0)); 
			}
			
			
			int effect = partyParkMapper.appoint(hm);
			
			if(effect!=1){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "预约失败");
				return m;
			}
			

			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "预约成功");

		
		return m;
	}
	
	
	
	
	//获取预约列表
	@Override
	public Map<String, Object> getAppointmentList(String token,String party_appointmentID, String page_size, String page_index, String skip, String rows) throws Exception {
	
		Map<String, Object> m = new HashMap();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			
			HashMap hm=MyTools.pageIndexToSkip(page_size, page_index, skip, rows);
			hm.put("cUserID", c_user_id); 
			hm.put("party_appointmentID", party_appointmentID); 
			
			List<Appointment> list=partyParkMapper.getAppointmentList(hm);
		

			m.put(ApplicationUtils.DATASET, list);
			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "查询成功");

		
		return m;
	}
	
	

	
	//反馈
		@Override
		public Map<String, Object> cancelAppointment(String token, String party_appointmentID) throws Exception {
		
			Map<String, Object> m = new HashMap();
			
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
			if (t != null) {
				return t;
			}
//			String c_user_id = jedisCache.lindex(token, 0);
				
				


				int count=partyParkMapper.cancelAppointmentCheckID(party_appointmentID);
				if(count<1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "请输入有效id");
					return m;
				}
				int effect=partyParkMapper.cancelAppointment(party_appointmentID);
				if(effect<1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "取消失败");
					return m;
				}
				
				

				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "取消成功");

			
			return m;
		}
	
	//反馈
	@Override
	public Map<String, Object> feedback(String token, String party_appointmentID, String feedback) throws Exception {
	
		Map<String, Object> m = new HashMap();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
//		String c_user_id = jedisCache.lindex(token, 0);
			
			
			HashMap hm=new HashMap();
			hm.put("party_appointmentID", party_appointmentID); 
			hm.put("feedback", feedback); 
			
			int count=partyParkMapper.feedbackCheckID(hm);
			if(count<1){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "请输入有效id");
				return m;
			}
			
			int effect=partyParkMapper.feedback(hm);
		
			if(effect<1){
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "反馈失败");
				return m;
			}

			m.put(ApplicationUtils.STATUS, "1");
			m.put(ApplicationUtils.MSG, "反馈成功");

		
		return m;
	}
		

		
		
}
